<template>
    <h2>显示会员</h2>

姓名：
<input type="text" v-model="mname">

会员等级：<select  v-model="Did">
        <option :value="-1">---请选择---</option>
        <option v-for="item in bb" :value="item.did">{{ item.dname }}</option>
        </select>

   

        <button @click="SouSuo"> 搜索</button>
    <table >
        <thead>
            <tr>
            <th>会员id</th>
            <th>会员名称</th>
            <th>性别</th>
            <th>手机号</th>
            <th>会员等级</th>
            <th>积分</th>
            <th>累计消费</th>
            <th>注册时间</th>
            <th>操作</th>
            </tr>
    
        </thead>
            <tbody v-for="item in aa">
    
            <tr>
            <th>{{ item.mid }}</th>
            <th>{{ item.mname }}</th>
            <th>{{ item.sex==1?"男":"女" }}</th>
            <th>{{item.phone.substring(0,4)+'****'+item.phone.substring(7,11) }}</th>
            <th>{{ item.dname }}</th>
            <th>{{ item.jiFen }}</th>
            <th>￥：{{ item.price.toFixed(2) }}</th>
            <th>{{ item.zhuce.substring(0,10)+ '-'+item.zhuce.substring(11,19)}}</th>
            <th><button @click="IseDel(item.mid)">删除</button></th>
            </tr>


            </tbody>
    
    </table>
    
    
    
    
    </template>
    
    <script setup lang="ts">


        import axios from 'axios';
import {onMounted, ref} from 'vue';

   
 const aa = ref([{
    mid: 0,
    mname: "",
    sex: 0,
    phone: "",
    did: 0,
    jiFen: 0,
    price: 0,
    zhuce: "2024-12-16T02:15:57.706Z",
    isDel: true,
    dname: "",
    xiaoFeie: 0


        }]);


        onMounted(()=>{
            ShowMe();
            XiaLa();
        })
        

        const mname =ref('');
        const Did=ref(-1);
         const ShowMe=()=>{

            axios.get('https://localhost:7296/api/Member/ShowMe',{
                params:{

                    Mname:mname.value,
                    Did:Did.value,
                }
            }).then(res=>{

                        aa.value=res.data

                    }).catch(error=>{
                        console.log(error)
                    })

         }



         const bb =ref([{

     did: 0,
    dname: "",
    xiaoFeie: 0

            
         }])



         const XiaLa=()=>{

            axios.get('https://localhost:7296/api/Dengji/ShowDengji').then(res=>{

                    bb.value=res.data
            })
            .catch(error=>{
                console.log(error);
            })
         }
    





         const SouSuo=()=>{

            ShowMe();
         }


            const IseDel =(mid:number)=>{


                if(!confirm('确定删除吗'))
            {
                return ;
            }

                axios.delete('https://localhost:7296/api/Member/IsDel',{

                    params:{

                        id:mid,
                    }

                })
                .then(res=>{

                    if(res.data>0)
                {
                    alert('删除成功')
                    ShowMe();
                }
                else
                {
                    alert('删除失败')
                }
                })
                .catch(eror=>{
                    console.log(eror)
                })


            }


    </script>